package view;

import java.awt.Color;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

/**
 * This class manages the Preview view window
 * 
 * The preview view displays the details of a selected meeting.
 * 
 * @author buthainahaldosary
 * @since May 31, 2013
 * @version $Revision: 1.0 $
 */
@SuppressWarnings("serial")
public class PreviewMeetingView extends JPanel{

	/**
	 * Non-editable text field/areas for a meeting.
	 */
	private JTextField topic, location, startDate,endDate, attendees;
	private JTextArea description;
	/**
	 * Save and send buttons.
	 */
	private JButton deleteBtn, editBtn;
	/**
	 * Date format to be used for displaying the date.
	 */
	private String dateFormat;
	/**
	 * Constructor
	 * @param  migLayout the used layout for the panel
	 */
	public PreviewMeetingView(MigLayout migLayout) {

		super(migLayout);		
		dateFormat = "yyyy.MMMMM.dd hh:mm aaa";
		setupComponents();
	}
	/**
	 * Setup components in this panel
	 */
	private void setupComponents(){

		// Initialize
		startDate = new JTextField();
		endDate = new JTextField();
		topic = new JTextField();
		location = new JTextField();
		attendees = new JTextField();
		description = new JTextArea();
		JPanel toolbar = new JPanel(new MigLayout("fillx"));
		deleteBtn = new JButton("Delete",IconsManager.getImageIcon("small/cross.png"));
		deleteBtn.setToolTipText("Click this button to delete a meeting.");
		
		editBtn=new JButton("Edit...",IconsManager.getImageIcon("small/document-pencil.png"));
		editBtn.setToolTipText("Click this button to edit a meeting.");
		JPanel details = new JPanel(new MigLayout("fillx", ""));
		
		JScrollPane descriptionScroll = new JScrollPane(description);
		
		// Set properties
		startDate.setEditable(false);
		endDate.setEditable(false);
		topic.setEditable(false);
		location.setEditable(false);
		attendees.setEditable(false);
		description.setEditable(false);
		
		// add
		toolbar.add(editBtn, "push, al right");
		toolbar.add(deleteBtn, "al right");
		toolbar.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY));
		this.add(toolbar, "wrap, growx");
		details.add(new JLabel("Topic:"));
		details.add(topic, "wrap, growx");
		details.add(new JLabel("Location:"));
		details.add(location, "wrap, push, growx");
		details.add(new JLabel("Start Date:"));
		details.add(startDate, "wrap, growx");
		details.add(new JLabel("End Date:"));
		details.add(endDate, "wrap, growx");
		details.add(new JLabel("Attendees:"));
		details.add(attendees, "wrap, growx");
		details.add(descriptionScroll, "span 2, growx, h 50:200:400");
		this.add(details,"wrap, growx");
	}
	/**
	 * 
	 * @param topicText text to be set for the topic
	 */
	public void setTopic(String topicText) {
		this.topic.setText(topicText);
		
	}
	/**
	 * 
	 * @param locationText text to be set for the location
	 */
	public void setLocation(String locationText) {
		this.location.setText(locationText);
		
	}
	/**
	 * 
	
	 * @param start Timestamp
	 */
	public void setStartDate(Timestamp start) {
		String d = new SimpleDateFormat(dateFormat).format(start);
		this.startDate.setText(d);
		
	}

	/**
	 * 
	 * @param timestamp to be used to be set for the end date text
	 */
	public void setEndDate(Timestamp timestamp) {
		String d = new SimpleDateFormat(dateFormat).format(timestamp);
		this.endDate.setText(d);
		
	}
	/**
	 * 
	 * @param attendeesText text to be set for the attendees
	 */
	public void setAttendees(String attendeesText) {
		this.attendees.setText(attendeesText);
		
	}
	/**
	 * 
	 * @param description to be set for the description
	 */
	public void setDescriptionText(String description)
	{
		this.description.setText(description);
	}

	/**
	 * 
	
	 * @return topic as text */
	public String getTopic() {
		return topic.getText();
	}
	
	/**
	 * 
	
	 * @return start date as text */ 
	public String getStartDate() {
		return startDate.getText();
	}
	/**
	 * 
	
	 * @return end date as text */
	public String getEndDate() {
		return endDate.getText();
	}
	/**
	 * 
	
	 * @return attendees as text */
	public String getAttendees() {
		return attendees.getText();
	}
	/**
	 * 
	
	 * @return description as text */
	public String getDescription() {
		return description.getText();
	}
	/**
	 * 
	
	 * @return delete JButton */
	public JButton getDeleteBtn() {
		return deleteBtn;
	}
	/**
	 * 
	
	 * @return edit JButton */
	public JButton getEditBtn() {
		return editBtn;
	}
	


}
